from django.http import HttpResponse
from django.utils.deprecation import MiddlewareMixin
from django.conf import settings


class FaviconMiddleware(MiddlewareMixin):
    """修改ico的请求地址"""

    def process_request(self, request):
        if request.path == '/favicon.ico':
            icon = settings.MEDIA_ROOT.joinpath('setting', 'favicon.ico')
            with open(icon, 'rb') as f:
                return HttpResponse(f.read(), content_type="image/x-icon")
